package com.hong.base;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.api.RedissonReactiveClient;
import org.redisson.api.RedissonRxClient;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;

public class RedissonClientFactory {


    public static RedissonClient getSingleRedissonClient(){
        return Redisson.create(getSingleBaseConfig());
    }
    public static RedissonReactiveClient getSingleRedissonClientReac(){
        return Redisson.createReactive(getSingleBaseConfig());
    }
    public static RedissonRxClient getSingleRedissonClientRx(){
        return Redisson.createRx(getSingleBaseConfig());
    }

    public static RedissonClient getClusterRedissonClient(){
        return Redisson.create(getClusterBaseConfig());
    }

    private static Config getSingleBaseConfig(){
        Config config = getConfig();
        SingleServerConfig serverConfig = config.useSingleServer()
                .setAddress("redis://127.0.0.1:6379")
                .setTimeout(100000)
                .setConnectionPoolSize(5)
                .setConnectionMinimumIdleSize(2);
        return config;
    }

    private static Config getClusterBaseConfig(){
        Config config = getConfig();
        ClusterServersConfig serverConfig = config.useClusterServers()
                .addNodeAddress("redis://172.16.24.2:6379")
                .addNodeAddress("redis://172.16.24.4:6379")
                .addNodeAddress("redis://172.16.24.6:6379").setPassword("uB5EDZiNVIsg");
        return config;
    }

    private static Config getConfig(){
        Config config = new Config();
        config.setTransportMode(TransportMode.NIO);
        return config;
    }
}
